package com.java.util.resp;

import java.io.Serializable;
import java.util.List;

public class TableRespone implements Serializable{
	private static final long serialVersionUID = 1L;

	/** 总记录数 */
	private long total;

	/** 列表数据 */
	private List<?> rows;

	/** 消息状态码 */
	private int code;

	/** 消息内容 */
	private String msg;

	/**
	 * 表格数据对象
	 */
	public TableRespone() {
	}

	/**
	 * 分页
	 * 
	 * @param list  列表数据
	 * @param total 总记录数
	 */
	public TableRespone(List<?> list, int total) {
		this.code = 200;
		this.msg = "SUCCESS";
		this.rows = list;
		this.total = total;
	}
	public TableRespone(List<?> list, long total) {
		this.code = 200;
		this.msg = "SUCCESS";
		this.rows = list;
		this.total = total;
	}
	
	/**
	 * 获取分页偏移量
	 * 
	 * @param pageIndex  分页页数
	 * @param pageSize 每页总记录数
	 */
	public static int getOffset(int pageIndex , int pageSize){
		int pOffset = 0;
		if(pageIndex > 0){
			pOffset = (pageIndex-1) * pageSize;
			pOffset = pOffset -1;
			if(pOffset < 0)
				pOffset = 0;
		}
		return pOffset;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public List<?> getRows() {
		return rows;
	}

	public void setRows(List<?> rows) {
		this.rows = rows;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
